using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Services;

namespace MainGame.Menu
{

  public enum scopa
  {
    yellow,
    red,
    violet,
  }

  public class BackgroundMenu : BaseMenu
  {
    SpriteBatch spriteBatch;
    private Color colorBackground = Color.Transparent;
    private Texture2D background2, box, boxLegnoso, logo;

    public BackgroundMenu(Game game, MenuDepths depth)
      : base(game, depth)
    {
      spriteBatch = Game.GetContext().SpriteBatch;

      background = game.Content.Load<Texture2D>(@"Images//Menu//Venice-0");
      background2 = game.Content.Load<Texture2D>(@"Images//Menu//Venice-1");
      box = game.Content.Load<Texture2D>(@"Images//Menu//roundedBox");
      boxLegnoso = game.Content.Load<Texture2D>(@"Images//Menu//sfondoGames");
      logo = game.Content.Load<Texture2D>(@"Images//Menu//BriscoLogo");

      bounds = game.GraphicsDevice.Viewport.Bounds;
    }

    protected override void Dispose(bool disposing)
    {
      base.Dispose(disposing);
    }

    private float delta, delta2, time = 0.0f;
    private int segno = 1, clr = 0;
    private bool isFading = false;

    public override void Update(GameTime gameTime)
    {
      time += gameTime.dt();
      if (time > 15.0f)
      {
        isFading = true;
        time = 0.0f;
      }

      if (isFading)
      {
        delta += 0.0123f;
        delta2 += 0.005f * segno;
        clr++;
      }

      if (delta >= 1.0f)
      {
        delta = 0.0f;
        var oldBackground = background;
        background = background2;
        background2 = oldBackground;

        colorBackground = Color.Transparent;

        segno = segno * -1;
        isFading = false;
      }
      else
      {
        colorBackground = Color.Lerp(Color.Transparent, Color.White, delta);
      }
    }

    public override void Draw(GameTime gameTime)
    {
      base.Draw(gameTime);

      spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

      // Background
      spriteBatch.Draw(background, bounds, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, (float)DrawOrder / (float)MenuDepths.numMenus);
      spriteBatch.Draw(background2, bounds, null, colorBackground, 0, Vector2.Zero, SpriteEffects.None, (float)DrawOrder / (float)MenuDepths.numMenus);

      // Box
      spriteBatch.Draw(box, new Rectangle(70, 50, 270, 240), null, new Color(100, 100, 100, 100), 0, Vector2.Zero, SpriteEffects.None, (float)DrawOrder / (float)MenuDepths.numMenus);
      spriteBatch.Draw(boxLegnoso, new Rectangle(70, 310, 270, 60), null, new Color(50, 200, 200, 160), 0, Vector2.Zero, SpriteEffects.None, (float)DrawOrder / (float)MenuDepths.numMenus);

      //LOGO
      spriteBatch.Draw(logo, new Rectangle(320, 40, 500, 302), null, Color.White);
      //spriteBatch.Draw(logo, new Rectangle(320, 40, 500, 302), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);

      spriteBatch.End();
    }
  }
}
